<div id="main">
  <div class="scroll-panel">
    <%= simple_form_for [storytime, :dashboard, @navigation] do |f| %>
      <div class="scroll-panel-header">
        <%= link_to "#", class: "btn btn-default btn-icon pull-left visible-xs visible-sm", data: { toggle: "off-canvas",  target: "#dashboard-nav" } do %>
          <i class="icon-st-icons-st-logo"></i>
        <% end %>
        <div class="pull-right">
          <%= link_to "Cancel", [storytime, :dashboard, Storytime::Navigation], class: "btn btn-primary btn-sm btn-outline" %>
          <%= f.submit "Save", class: "btn btn-sm btn-primary btn-outline" %>
        </div>
        <h3 class="scroll-panel-title"><%= header %></h3>
      </div>
      <div class="scroll-panel-body">
        <div class="row">
          <div class="col-sm-6">
            <%= f.input :name %>
          </div>
          <div class="col-sm-6">
            <%= f.input :handle, disabled: @navigation.persisted? %>
          </div>
        </div>

        <div>
          <table class="table">
            <thead>
              <tr>
                <th style="width: 40%;">Link Text</th>
                <th style="width: 40%;">Link</th>
                <th></th>
              </tr>
            </thead>
            <tbody id="links">
              <%= f.simple_fields_for :links do |link| %>
                <% if link.object.url.present? || link.object.errors[:url].present? %>
                  <%= render "external_link_fields", f: link %>
                <% else %>
                  <%= render "#{link.object.linkable.type.split("::").last.downcase}_link_fields", f: link %>
                <% end %>
              <% end %>
            </tbody>
          </table>
          <div class="btn-group">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
              Add a Link <span class="caret"></span>
            </button>
            <ul class="dropdown-menu left" role="menu">
              <li><%= link_to_add_association "Page Link", f, :links, partial: "page_link_fields", :"data-association-insertion-node" => "#links", :"data-association-insertion-method" => "append" %></li>
              <li><%= link_to_add_association "Blog Link", f, :links, partial: "blog_link_fields", :"data-association-insertion-node" => "#links", :"data-association-insertion-method" => "append" %></li>
              <li><%= link_to_add_association "External Link", f, :links, partial: "external_link_fields", :"data-association-insertion-node" => "#links", :"data-association-insertion-method" => "append" %></li>
            </ul>
          </div>
          
        </div>
      </div>
    <% end %>
  </div>
</div>